#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "gpio.h"
#include <pthread.h>

pthread_t Thread_key;

static unsigned int key_status = 0;

void thread_key(void *arg)
{
	int ret = 0;
	while(1)
	{
		ReadGpio(9,1,&ret);
		
		if (key_status == 0 && ret == 0)
		{
		   key_status = 1;
		}		
		else if (key_status == 1 && ret == 1)
		{
		   key_status = 0;
		   printf("Read gpio5_2=%d\n",ret);
		   system("curl -d \"cmd=event&uid=C9KA8D5WK1BCUG6GU151&event_type=60&msg=V_C9KA8D5WK1BCUG6GU151&debug=0\" \"http://push.iotcplatform.com/tpns\"");
		}

		usleep(10000);
	}

}

int key_main(void)
{
	int ret=-1;
	//system("devmem 0x200f00BC 32 0x00000000");
	InitGpio(9,1,GPIO_IN,1);
	pthread_create(&Thread_key, NULL, &thread_key, (void *)NULL);
}
